import * as CryptoJS from 'crypto-js'
let key = CryptoJS.enc.Utf8.parse('1WE4TY7IO023456F') // 十六位十六进制数密钥
let iv = CryptoJS.enc.Utf8.parse('2WSDR56YJKL90OIU') // 十六位十六进制数密钥偏移量
let CryptoTool = {
  // 解密
  decrypt: function (word) {
    let encryptedHexStr = CryptoJS.enc.Hex.parse(word)
    let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr)
    let decrypt = CryptoJS.AES.decrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 })
    let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8)
    return decryptedStr.toString()
  },
  // 加密方法
  encrypt: function (word) {
    let srcs = CryptoJS.enc.Utf8.parse(word)
    let encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.Pkcs7 })
    return encrypted.ciphertext.toString().toUpperCase()
  }
}

export default CryptoTool
